﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ProjectFitus.Models.RequestListAndStatusNamesCapsule>" %>
<script type="text/javascript" src="../../Scripts/requestListScript.js"></script>



    <div id="requestList">
        <%if (ViewData["morePagesToTheLeft"] == "true"){%>
            <%= Html.ActionLink("Fyrri 10 beiðnir", (ViewData["lastPage"]).ToString(), "Request" )%>
        <%} %>
        <%if (ViewData["morePagesToTheRight"] == "true"){%>
            <%= Html.ActionLink("Næstu 10 beiðnir", (ViewData["nextPage"]).ToString(), "Request" )%>
        <%} %>
    <table class="beidnitafla">
        <tr class="beidnitafla1">
            <th></th>
            <th>
                Titill beiðni:
            </th>
            <th>
                Tegund beiðni
            </th>
            <th>
                Staða
            </th>
            <th>
                Lögð fram dags:
            </th>
            <th>
                Beiðni sett fram af
            </th>

            <th>
                Seinast uppfært af
            </th>
            <th>
                Seinast uppfært dags:
            </th>
        </tr>
    <% foreach (var item in Model.requestList) { %>
    
        <tr class="beidnitafla2">
            <td>
                <a class="requestEditLinks" onclick="editRequest(<%: item.id %>)" id="<%: item.id %>" name="<%: item.id %>" >Nánar</a>
            </td>

            <td>
                <%:  item.requestTitle %>
            </td>

            <td class="beidnitafla3"> 
                <%: item.RequestType1.requestTypeName %>   
            </td>
     
            <td class="beidnitafla3">
                <%: item.AssignmentStatusListItem.statusName %>
            </td>
            
            <td class = "beidnitafla3">
                <%: item.dateCreated %>
            </td>

            <td class = "beidnitafla3">
                <%= Html.ActionLink( item.User.userName, "Details/"+item.requestedBy, "User") %> 
            </td>

            <%  var lastResponse = item.RequestResponses.Where(p => p.isActive == true).OrderByDescending(p => p.dateCreated).FirstOrDefault();
                    if (lastResponse != null) 
            {%>

                <td class="beidnitafla3">

                            <%= Html.ActionLink( lastResponse.User.userName, "Details/"+lastResponse.submittedBy, "User")%>     
                </td>

                <td class="beidnitafla3">
                     <%: String.Format("{0:g}", lastResponse.dateCreated) %> 
                </td>
            <%}%>

        </tr>
    
    <% } %>

    </table>
    <%if (ViewData["morePagesToTheLeft"] == "true"){%>
        <%= Html.ActionLink("Fyrri 10 beiðnir", (ViewData["lastPage"]).ToString(), "Request" )%>
    <%} %>
    <%if (ViewData["morePagesToTheRight"] == "true"){%>
        <%= Html.ActionLink("Næstu 10 beiðnir", (ViewData["nextPage"]).ToString(), "Request" )%>
    <%} %>

    </div>

    <div id="editRequestWindow"  style="border:1px solid pink; display:none;">

    <p><span id="requestType"></span>
    <span id="requesterUrl"></span></p>
    <p id="requestTitle"></p>
    <p id="requestDescription"></p>
    <ul id="responseList">
    </ul>
    <form action="/Request/Edit/" method="post">
    <input id="requestIdBeingEdited" name="requestIdBeingEdited" type="hidden" value="0" />
    <input type="hidden" id = "pageNo" name="pageNo" value="<%: ViewData["pageNo"] %>"/> 
    <input type="hidden" id = "ctr" name="ctr" value="<%: ViewData["ctr"] %>" />
    <label for="responseSumbitText">Uppfæra spurningu/svar:</label>
    <br />
    
    <textarea id="responseSubmitText" name="responseSubmitText" cols="50" rows="6"></textarea>
    <br />
    <% if (Model.statusList != null)
       {%>
            <%: Html.DropDownList("statusId", Model.statusList)%>
     <%}%>
    <input type ="submit" value="Staðfesta" id="submitRequestChanges" />
       

         </form>
     <button id="stopRequestEdit" name="stopRequestEdit">Til Baka</button>
    </div>

    		<script id="responseTemplate" type="text/x-jquery-tmpl">
                <li class="responseListItem">
                <p><span id="responseTitle${responseId}" onclick=showRequestResponse(${responseId})>${responseTitle}</span> - Uppfært af <a href="/User/Details/${responderId}">${responderUrlText}</a></p>
                <p class="responseText" id="responseText${responseId}">${responseText}</p>
                </li>
            </script> 

